<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="<?php echo $this->_webroot('skin/css/admin.css'); ?>">
<link rel="stylesheet" type="text/css" href="<?php echo $this->_webroot('skin/css/main.css'); ?>">
<style>
.green {color:green;}
.red {color:red;}
.edit span{background:#efefef;}
</style>
</head>
<body>

<psp:tags     htmlname='messagebox'  iconname='messagebox' />

<form id="form1" name="form1" method="post" action="<?php echo $this->_url('admin/area/add/?parent_id='.$parent_id.'&area_type='.$area_type);?>" onsubmit="return check();">
<input type="hidden" id="area_edit" value="1">
<div id="maincontent">
	<div class="wrap">
	<div class="crumbs">当前位置 &gt;&gt; 系统设置 &gt;&gt; 地域列表</div>
        <hr />
      <div class="seachbox">
        <div class="content2">
            <table class="form-table">
            	<tbody>
            	  <tr>
                   	<td width="78px">
                   		第<?php echo $area_type+1;?>级地址目录
                   	</td>
					<td width="100px">
						<input class="small-text" type="text" name="data[area][area_name]" id="textfield" />
					</td>
                  	<td width="">
                  		<input class="regular-button" type="submit" name="button" id="button" value="添加" />
                  	</td>
                  </tr>
                </tbody>
            </table>
        </div>
    </div>

	<div class="infobox">
	<h3><span class="left">地域管理</span><span class="right" style="margin-right:15px;">
	<a href="<?php echo $this->_url('admin/area/index/'.$parent_id_last['area']['parent_id'].'/'.($area_type-1));?>">	
						返回上一级</a></span> </h3>
    <div class="content2">
		<table class="list_table">
			<thead>
				<tr style="text-align:center;">
					<th width="20%">ID</thd>
					<th>地域名称</th>
					<th width="30%">操作</th>
				</tr>
			</thead>
			<tbody>
				<?php if($areas_info) {
				foreach($areas_info as $val) { ?>
				<tr style="text-align:center;">
					<td width="20%"><?php echo $val['area']['id'];?>.</td>
					<td id="area_id_<?php echo $val['area']['id'];?>">
					<span onclick="edit_name(this,<?php echo $val['area']['id'];?>)">&nbsp;<?php echo $val['area']['area_name'];?>&nbsp;</span></td>
					<td width="30%">
					<a href="<?php echo $this->_url('admin/area/index/'.$val['area']['id'].'/'.($area_type+1));?>">编辑</a>					
					<a href="<?php echo $this->_url('admin/area/del/'.$val['area']['id'].'?parent_id='.$parent_id.'&area_type='.$area_type);?>" onclick="return confirm('确定要删除这个分类及它下头的所有子分类吗？');">删除</a></td>
				</tr>
				<?php }?>

				<?php } else { ?>
				<tr>
					<td colspan="4">没有信息列表!</td>
				</tr>
				<?php } ?>
			</tbody>
		</table>
</div></div></div></div>
</form>
</body>
</html>
<script language="JavaScript" src="<?php echo $this->_webroot('servtools/ajax_client/ajax.js'); ?>"></script>
<script language="JavaScript">
<!--
var name_value;
function edit_name(span,id) {
	right = document.getElementById("area_edit").value;	
	if(right != '0'){
		obj = document.getElementById("area_id_"+id);
		name_value = span.innerHTML;
		name_value = name_value.replace(/&nbsp;/ig,"");
		obj.innerHTML = '<input style="width:60px" type="text" class="small-text" id="input_area_id_' + id + '" value="' + name_value + '" onblur="edit_name_post(this,' + id + ')" maxlength="100"  />';
		document.getElementById("input_area_id_"+id).focus();
	}else{
		ShowMessageBox("对不起，您没有权限不能修改！",'0');
		location.href="<?php echo $this->_url('admin/area/add/?parent_id='.$parent_id.'&area_type='.$area_type);?>";
	}
}

function edit_name_post(input,id) {
	var obj = document.getElementById("area_id_"+id);
	if(name_value==input.value) {
		obj.innerHTML = '<span onclick="edit_name(this,' + id + ')">&nbsp;' + name_value + '&nbsp;</span>';
	} else {
		if(input.value!=""){
			ajax("<?php echo $this->_url('admin/area/add/?parent_id='.$parent_id.'&area_type='.$area_type);?>","POST","id="+id+"&v="+input.value,function(data){			
				if(data==1) {
					obj.innerHTML = '<span onclick="edit_name(this,' + id + ')">&nbsp;' + input.value + '&nbsp;</span>';
				} else {
					obj.innerHTML = '<span onclick="edit_name(this,' + id + ')">&nbsp;' + name_value + '&nbsp;</span>';
				}
			});
		}else{
			obj.innerHTML = '<span onclick="edit_name(this,' + id + ')">&nbsp;' + name_value + '&nbsp;</span>';
		}
	}
}
//-->
function check(){
	var text=document.getElementById("textfield").value;
	if(text.length==0){
		ShowMessageBox("请输入地址目录",'0');
		return false;
		}
	return true;
}
</script>